<%--
  Created by IntelliJ IDEA.
  User: 81116
  Date: 2023/12/8
  Time: 17:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增试题</title>
    <jsp:include page="teacher_menu.jsp"></jsp:include>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- 引入各种CSS样式表 -->
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/index.css">
    <%--    图标--%>
    <link rel="stylesheet" href="icon/iconfont.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/c/font_4336496_3iu2a7l8bg8.css">
    <!--引入jquery和bootstrap -->
    <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/laydate.js"></script>
    <link href="css/laydate.css" rel="stylesheet">

    <style>
        #content{
            margin-left: 25%;
            margin-top: 30px;
        }
        .part {
            background-color: white;
            border-radius: 2px;
            font-size: large;
            box-shadow: 1px 1px 1px 1px #c4e3f3;
            padding-top: 20px;
            padding-left: 30px;
            padding-right: 20px;
            width: 800px;
            position: relative;
        }
        .part input[type=text], select, textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid royalblue;
            border-radius: 4px;
            box-sizing: border-box;
            margin-top: 6px;
            margin-bottom: 16px;

        }
        .my-select {
            width: 100%;
            padding: 12px;
            border: 1px solid royalblue;
            border-radius: 4px;
            box-sizing: border-box;
            margin-top: 6px;
            margin-bottom: 16px;
            color: dimgray;
        }

    </style>
</head>
<body>
<%
    String mess=(String)session.getAttribute("message");
    if(mess!=null && !"".equals(mess)){
%>
<script type="text/javascript">
    alert("<%=mess%>");
</script>
<%
        session.setAttribute("message", "");
    } %>
<div id="content">
    <div class="part">
        <div style="text-align:center;font-size: 22px;background-color: #2e6da4; width: 100%;height: 50px">
            <h2 style="padding-top: 10px;color: whitesmoke">新增试题</h2>
        </div>
        <br><br>
        <form action="${pageContext.request.contextPath}/addQuestion" method="post" id="addQuestion">
            课程名称：<input type="text" id="c_name" name="c_name" size="20px" placeholder="请输入课程名称"><br>
            试题类型：<br><select class="my-select" id="q_type" name="q_type">
            <option value="单选题">单选题</option>
            <option value="多选题">多选题</option>
            <option value="判断题">判断题</option>
        </select><br>
            标准答案：<input type="text" id="q_standard" name="q_standard" size="20px" placeholder="请输入标准答案"><br>
            选项A：<input type="text" id="op_A" name="op_A" size="20px" placeholder="请输入选项A"><br>
            选项B：<input type="text" id="op_B" name="op_B" size="20px" placeholder="请输入选项B"><br>
            选项C：<input type="text" id="op_C" name="op_C" size="20px" placeholder="请输入选项C"><br>
            选项D：<input type="text" id="op_D" name="op_D" size="20px" placeholder="请输入选项D"><br>
            试题内容：<textarea id="q_content" name="q_content" placeholder="请输入试题内容"
                           style="height:200px"></textarea><br><br>
            <input type="button" value="添加" class="btn btn-success" onclick="add_question()" style="font-size: 20px">
            <input type="button" value="返回" class="btn btn-warning" onclick='location.href=("questionBank.jsp")' style="font-size: 20px"><br><br>
        </form>
    </div>
</div>

<script>
    function add_question(){
        var c_name=$("#c_name").val();
        var q_standard=$("#q_standard").val();
        var op_A=$("#op_A").val();
        var op_B=$("#op_B").val();
        var op_C=$("#op_C").val();
        var op_D=$("#op_D").val();
        var q_content=$("#q_content").val();
        if(c_name===null || c_name===""){
            alert("课程名称不可为空，请填写！");
            return;
        }else if(q_standard===null || q_standard===""){
            alert("标准答案不可为空，请填写！");
            return;
        }else if(op_A===null || op_A==="") {
            alert("选项A不可为空，请填写！");
            return;
        }else if(op_B===null || op_B==="") {
            alert("选项B不可为空，请填写！");
            return;
        }else{
            //判断是否是判断题，只有判断题C,D选项可以为空
            var q_type=document.getElementById("q_type");//获取select对象
            var index=q_type.selectedIndex;//获取选中项
            if(q_type.options[index].value==="单选题" || q_type.options[index].value==="多选题"){
                if(op_C===null || op_C===""){
                    alert("选项C不可为空，请填写！");
                    return;
                }else if(op_D===null || op_D===""){
                    alert("选项D不可为空，请填写！");
                    return;
                }
            }
            if(q_content===null || q_content==="") {
                alert("试题内容不可为空，请填写！");
                return;
            }else{//均不为空，或判断题只有CD为空，可以提交
                alert("确定提交");
                $("#addQuestion").submit();
                return false;
            }
        }
    }
</script>
</body>
</html>
